/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.geftu.model;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import org.hibernate.annotations.Cascade;
import org.hibernate.transform.ToListResultTransformer;

/**
 *
 * @author jorgenei
 */
@Entity
@Table(name = "tb_projeto", catalog = "bddefeitos", schema = "public")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Projeto.findAll", query = "SELECT t FROM Projeto t"),
    @NamedQuery(name = "Projeto.findByIdproj", query = "SELECT t FROM Projeto t WHERE t.idproj = :idproj"),
    @NamedQuery(name = "Projeto.findByNomeprojeto", query = "SELECT t FROM Projeto t WHERE t.nomeprojeto = :nomeprojeto"),
    @NamedQuery(name = "Projeto.findByDescricao", query = "SELECT t FROM Projeto t WHERE t.descricao = :descricao"),
    @NamedQuery(name = "Projeto.findByDtinicial", query = "SELECT t FROM Projeto t WHERE t.dtinicial = :dtinicial"),
    @NamedQuery(name = "Projeto.findByDtfinal", query = "SELECT t FROM Projeto t WHERE t.dtfinal = :dtfinal"),
    @NamedQuery(name = "Projeto.findByExcluido", query = "SELECT t FROM Projeto t WHERE t.excluido = :excluido")})
public class Projeto implements Serializable {

    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "projeto")
    private Collection<Participa> ParticipaCollection;
    private static final long serialVersionUID = 1L;
    @Id
    @SequenceGenerator(name = "idproj", sequenceName = "projeto_seq", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "idproj")
    @Basic(optional = false)
    @Column(name = "idproj", nullable = false)
    private Integer idproj;
    @Column(name = "nomeprojeto", length = 255)
    private String nomeprojeto;
    @Column(name = "descricao", length = 255)
    private String descricao;
    @Column(name = "dtinicial", length = 20)
    private String dtinicial;
    @Column(name = "dtfinal", length = 20)
    private String dtfinal;
    @Column(name = "excluido")
    private Boolean excluido;
    @OneToMany(mappedBy = "projeto", targetEntity = Modulo.class, fetch = FetchType.LAZY)
    @Cascade(org.hibernate.annotations.CascadeType.ALL)
    private Collection<Modulo> modulo;

    public Projeto() {
    }

    public Projeto(Integer idproj) {
        this.idproj = idproj;
    }

    public Integer getIdproj() {
        return idproj;
    }

    public void setIdproj(Integer idproj) {
        Integer oldIdproj = this.idproj;
        this.idproj = idproj;
        changeSupport.firePropertyChange("idproj", oldIdproj, idproj);
    }

    public String getNomeprojeto() {
        return nomeprojeto;
    }

    public void setNomeprojeto(String nomeprojeto) {
        String oldNomeprojeto = this.nomeprojeto;
        this.nomeprojeto = nomeprojeto;
        changeSupport.firePropertyChange("nomeprojeto", oldNomeprojeto, nomeprojeto);
    }

    public String getDescricao() {
        return descricao;
    }

    public void setDescricao(String descricao) {
        String oldDescricao = this.descricao;
        this.descricao = descricao;
        changeSupport.firePropertyChange("descricao", oldDescricao, descricao);
    }

    public String getDtinicial() {
        return dtinicial;
    }

    public void setDtinicial(String dtinicial) {
        String oldDtinicial = this.dtinicial;
        this.dtinicial = dtinicial;
        changeSupport.firePropertyChange("dtinicial", oldDtinicial, dtinicial);
    }

    public String getDtfinal() {
        return dtfinal;
    }

    public void setDtfinal(String dtfinal) {
        String oldDtfinal = this.dtfinal;
        this.dtfinal = dtfinal;
        changeSupport.firePropertyChange("dtfinal", oldDtfinal, dtfinal);
    }

    public Boolean getExcluido() {
        return excluido;
    }

    public void setExcluido(Boolean excluido) {
        Boolean oldExcluido = this.excluido;
        this.excluido = excluido;
        changeSupport.firePropertyChange("excluido", oldExcluido, excluido);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (getIdproj() != null ? getIdproj().hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Projeto)) {
            return false;
        }
        Projeto other = (Projeto) object;
        if ((this.getIdproj() == null && other.getIdproj() != null) || (this.getIdproj() != null && !this.idproj.equals(other.idproj))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return getNomeprojeto();
    }

    @XmlTransient
    public Collection<Participa> getParticipaCollection() {
        return ParticipaCollection;
    }

    public void setParticipaCollection(Collection<Participa> ParticipaCollection) {
        this.ParticipaCollection = ParticipaCollection;
    }

    /**
     * @return the modulo
     */
    public Collection<Modulo> getModulo() {
        return modulo;
    }

    /**
     * @param modulo the modulo to set
     */
    public void setModulo(Collection<Modulo> modulo) {
        this.modulo = modulo;
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }

}
